/**
 * https://leetcode.cn/problems/minimum-window-substring/submissions/559879959/
 * 76. 最小覆盖子串
 * difficulty, 陈贝纯 2024.08.30
 * 滑动窗口
 */


class Solution {
public:
    string minWindow(string s, string t) {
        map<char,int> mp;
        for(int i=0;i<t.length();++i)
        mp[t[i]]++;
        int j=0;
        int d=mp.size();
        string ss;
        for(int i=0;i<s.length();++i){
            mp[s[i]]--;
            if(d>0&&mp[s[i]]==0)
            d--;
            if(d==0)
            {
                while(mp[s[j]]<0){
                mp[s[j]]++;
                j++;
                }
            if(ss.length()==0||ss.length()>i-j+1)
            ss=s.substr(j,i-j+1);
            }
        }
        return ss;
    }
};

